<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Http\Request;

/**
 * Class CardUrlLinks
 *
 * @package App\Model
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Query\Builder|\App\Model\CardUrlLinks onlyTrashed()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Query\Builder|\App\Model\CardUrlLinks withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\Model\CardUrlLinks withoutTrashed()
 * @mixin \Eloquent
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\CardUrlLinks newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\CardUrlLinks newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\CardUrlLinks query()
 * @property int $id 主键
 * @property int|null $user_id 名片id
 * @property string $title 标题
 * @property string $url 链接地址
 * @property string $logo_picture_path logo图片地址
 * @property \Illuminate\Support\Carbon $created_at 创建时间
 * @property \Illuminate\Support\Carbon $updated_at 修改时间
 * @property \Illuminate\Support\Carbon|null $deleted_at 删除时间
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\CardUrlLinks whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\CardUrlLinks whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\CardUrlLinks whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\CardUrlLinks whereLogoPicturePath($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\CardUrlLinks whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\CardUrlLinks whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\CardUrlLinks whereUrl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\CardUrlLinks whereUserId($value)
 */
class CardUrlLinks extends Model
{
    use SoftDeletes;

    protected $table = 'card_url_links';

    protected $primaryKey = 'id';

    protected $dates = ['deleted_at'];

    public function add(Request $request)
    {
        $data = $request->input();

        if (!$request->isMethod('PUT')) {
            $this->user_id = $request->user()->id;
        }
        $this->title = $data['title'];
        $this->url = $data['url'];
        $this->logo_picture_path = $data['logo'];
        return $this->save();
    }
}
